package com.aqie.easy.stack;

/**
 * 1021. 删除最外层的括号
 * todo
 */
public class RemoveOuterParentheses {
    public static String removeOuterParentheses(String S) {
        StringBuilder result = new StringBuilder();
        int length = 0;
        for(int i = 0; i < S.length(); i ++){
            if (S.charAt(i) == '('){
                if (++length > 1) result.append('(');
            }else {
                if (-- length > 0) result.append(')');
            }
        }
        return result.toString();
    }

    public static void main(String[] args) {
        String s = "(()())(())";
        System.out.println(removeOuterParentheses(s));
    }
}
